﻿using log4net;
using MyWebApp.Common.Entity;
using MyWebApp.Common.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyWebApp.Common.UIAttribute
{
    public class AccessLogFilterAttribute : ActionFilterAttribute
    {
        private static ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string url = filterContext.RequestContext.HttpContext.Request.RawUrl;
            //string actionname = filterContext.ActionDescriptor.ActionName;
            //string controlname = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            string ip = MvcIpHelper.GetClientIP(filterContext.RequestContext.HttpContext.Request);

            log.DebugFormat("{0} request: {1} from {2}", AuthUtil.GetCurrentUserID(),url, ip);
            base.OnActionExecuting(filterContext);
        }

    }
}